package aes.gui;

import javax.swing.JPanel;
import javax.swing.JLabel;

import java.awt.CardLayout;
import java.awt.Font;

import javax.swing.JOptionPane;
import javax.swing.JSeparator;
import javax.swing.JButton;
import javax.swing.JComboBox;

import aes.general.StudentControl;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.ArrayList;


/**
 * The Class StudentGetManualExamCopy. This Panel represent the part of Student UI.
 * 	In this Panel Student can view the list of Manual Exams that he did and request Copy of specific Exam
 */
public class StudentGetManualExamCopy extends JPanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JPanel jp=null;
	private static JComboBox comboBoxExams;

	/**
	 * Builds the panel.
	 *
	 * @param contentPane the content pane of Main Student Frame
	 */
	public StudentGetManualExamCopy(JPanel contentPane) {
		this.jp=contentPane;
		setLayout(null);
		
		JLabel lblViewCompletedManual = new JLabel("View Completed  Manual Exam");
		lblViewCompletedManual.setFont(new Font("Tempus Sans ITC", Font.BOLD, 21));
		lblViewCompletedManual.setBounds(155, 11, 330, 29);
		add(lblViewCompletedManual);
		
		JSeparator separator = new JSeparator();
		separator.setBounds(17, 51, 606, 2);
		add(separator);
		
		JButton btnBack = new JButton("Back");
		btnBack.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				comboBoxExams.removeAllItems();
				CardLayout cl = (CardLayout)(jp.getLayout());
				 cl.show(jp,"MainPanel");	
				
			}
		});
		btnBack.setBounds(155, 331, 105, 23);
		add(btnBack);
		
		JButton btnGetExam = new JButton("Dowload");
		btnGetExam.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				if(comboBoxExams.getSelectedItem() == null)
				{
					JOptionPane.showMessageDialog(null, "No selection", "Error",
							JOptionPane.ERROR_MESSAGE);
				}
				else
					StudentControl.downoadManualExamCopy((String)comboBoxExams.getSelectedItem());
			}
		});
		btnGetExam.setBounds(305, 331, 105, 23);
		add(btnGetExam);
		
		 comboBoxExams = new JComboBox();
		comboBoxExams.setBounds(186, 112, 74, 18);
		add(comboBoxExams);
		
		JLabel lblSelectExam = new JLabel("Select Exam :");
		lblSelectExam.setFont(new Font("Tahoma", Font.PLAIN, 12));
		lblSelectExam.setBounds(71, 109, 108, 23);
		add(lblSelectExam);
		
		JLabel lblClickgetExam = new JLabel("Click   \"Downlod\"   to download your Exam");
		lblClickgetExam.setFont(new Font("Tahoma", Font.BOLD, 13));
		lblClickgetExam.setBounds(71, 188, 380, 29);
		add(lblClickgetExam);
		
		fillexamscombobox();

	}

	private void fillexamscombobox() {
		StudentControl.GetmanualExamslist();
		
	}

	/**
	 * Invoked after the Panel is build . Fills the Combobox element of Panel with exams list.
	 *  There is no need for user to call this method usually. 
	 * @param examstofill the list of ExamId's
	 */
	public static void fillcomboBoxExams(ArrayList<String> examstofill) {
		
		if (examstofill.get(0).equals("error")) return;
		
		for (int i=0;i<examstofill.size();i++)
			{
			comboBoxExams.addItem(examstofill.get(i));		
			}
		
			}
	
	
}
